<template>
	<view class="main-page user-page">
		<view class="user-info">
			<view class="avatar">
				<u-avatar :src="avatar" size="70"></u-avatar>
			</view>
			<view class="infos">
				<view class="name">
					{{userInfo.nickname}}
				</view>
				<view class="phone">
					{{userInfo.mobile}}
				</view>
			</view>
		</view>
		<view class="order-container">
			<view class="title">
				我的订单
				<text class="more" @tap="toUrls('/pages/user/order?tab=0')">全部订单&gt;&gt;</text>
			</view>
			<view class="items">
				<view class="item" @tap="toUrls('/pages/user/order?tab=1')">
					<view class="num">{{overview.sub}}</view>
					<view class="text">已下单</view>
				</view>
				<view class="item" @tap="toUrls('/pages/user/order?tab=2')">
					<view class="num">{{overview.confirm}}</view>
					<view class="text">已确认</view>
				</view>
				<view class="item" @tap="toUrls('/pages/user/order?tab=4')">
					<view class="num">{{overview.complete}}</view>
					<view class="text">已送货</view>
				</view>
			</view>
		</view>
		<view class="menus">
			<view class="item" @tap="toUrls('/pages/user/profile')">
				<u-icon class="left" name="setting" color="#999" size="22"></u-icon>
				<view class="text">个人资料</view>
				<u-icon class="right" name="arrow-right" color="#999" size="16"></u-icon>
			</view>
			<view class="item" @tap="toUrls('/pages/user/order')">
				<u-icon class="left" name="order" color="#999" size="22"></u-icon>
				<view class="text">我的订单</view>
				<u-icon class="right" name="arrow-right" color="#999" size="16"></u-icon>
			</view>
			<view class="item" @tap="toUrls('/pages/home/article?id=1')">
				<u-icon class="left"name="map" color="#999" size="22"></u-icon>
				<view class="text">联系我们</view>
				<u-icon class="right" name="arrow-right" color="#999" size="16"></u-icon>
			</view>
			<view class="item" @tap="toPhone">
				<u-icon class="left" name="phone" color="#999" size="22"></u-icon>
				<view class="text">客服电话</view>
				<u-icon class="right" name="arrow-right" color="#999" size="16"></u-icon>
			</view>
		</view>
	</view>
</template>

<script>
	import { userOverview } from '@/common/api.js';
	
	export default {
		data() {
			return {
				overview: {
					sub: 0,
					confirm: 0,
					complete: 0,
				}
			}
		},
		computed: {
			userInfo(){
				return this.$store.state.$userInfo
			},
			avatar(){
				return this.$store.state.$siteConfig.cdnUrl + this.$store.state.$userInfo.avatar
			}
		},
		onLoad() {
			this.getOverview()
		},
		methods: {
			 toUrls(url){
				 uni.navigateTo({
				 	url: url
				 })
			 },
			 toPhone(){
				 uni.makePhoneCall({
				 	phoneNumber: this.$store.state.$siteConfig.services_phone
				 });
			 },
			 getOverview(){
				 userOverview().then(res => {
					 this.overview = res
				 })
			 }
		}
	}
</script>

<style lang="scss">
	.user-page { min-height: 100vh; background-image: url('/static/images/my-bg2.png'); background-repeat: no-repeat;background-size: 100% auto;}
	.user-info { 
		padding: 130rpx 30rpx 0 30rpx; display: flex; color: #fff; flex-direction: row; align-items: center;
		.infos { 
			padding-left: 20rpx; 
			.name { font-weight: bold; font-size: 34rpx; padding-bottom: 20rpx;}
		}
	}
	.order-container {
		background-color: #fff; margin: 80rpx 30rpx 0 30rpx; padding: 20rpx; border-radius: 15rpx;
		.title {
			font-size: 30rpx; font-weight: bold;display: flex; justify-content: space-between; padding-bottom: 20rpx;		
			.more { font-weight: normal; color: #777; font-size: 24rpx;}
		}
		.items { 
			display: flex;
			.item { 
				flex:1; text-align: center; padding-bottom: 10rpx;
				.num { font-size: 42rpx; font-weight: 500; }
				.text { font-size: 26rpx; padding-top:14rpx;}
			}
		}
	}
	
	.menus { 
		background-color: #fff; border-radius: 15rpx; margin: 30rpx;
		.item { 
			display: flex;margin: 0 10rpx; padding: 26rpx 0;
			.text { flex: 1; font-size: 28rpx;}
			.u-icon { padding: 0 10rpx; }
		}
		.item+.item { border-top: 1px solid #eee; }
	}
</style>
